package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.dto.ParkingPaymentDto;
import com.ruoyi.system.domain.vo.ConsumerVo;
import com.ruoyi.system.domain.vo.ParkingPaymentVo;
import com.ruoyi.system.service.ParkingPaymentService;
import com.ruoyi.system.mapper.ParkingPaymentMapper;
import com.ruoyi.system.service.ParkingService;
import com.ruoyi.system.service.StatusService;
import com.ruoyi.system.service.VehicleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author Wl177
* @description 针对表【parking_payment】的数据库操作Service实现
* @createDate 2025-02-18 18:14:54
*/
@Service
public class ParkingPaymentServiceImpl extends ServiceImpl<ParkingPaymentMapper, ParkingPayment>
    implements ParkingPaymentService{

    @Override
    public ParkingPayment selectByOrderNo(String orderNo) {
        ParkingPayment byId = this.getById(orderNo);
        return byId;
    }
    @Resource
    ParkingService parkingService;
    @Resource
    VehicleService vehicleService;
    @Resource
    StatusService service;

    @Override
    public AjaxResult ParkingPaymentList(ParkingPaymentDto parkingPaymentDto) {
        Page<ParkingPayment> parkingPaymentPage = new Page<>(parkingPaymentDto.getPageNum(), parkingPaymentDto.getPageSize());

        Page<ParkingPaymentVo> parkingPaymentVoPage = new Page<>(parkingPaymentDto.getPageNum(), parkingPaymentDto.getPageSize());

        LambdaQueryWrapper<ParkingPayment> parkingPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();

        Page<ParkingPayment> page = this.page(parkingPaymentPage, parkingPaymentLambdaQueryWrapper);

        List<ParkingPaymentVo> parkingPaymentVos = new ArrayList<>();
        List<ParkingPayment> records = page.getRecords();
        for (int i = 0; i < records.size(); i++) {
            ParkingPaymentVo parkingPaymentVo = new ParkingPaymentVo();
            BeanUtils.copyBeanProp(parkingPaymentVo,records.get(i));
            Parking byId = parkingService.getById(records.get(i).getParkingId());
            Vehicle byId1 = vehicleService.getById(byId.getVehicleId());

            parkingPaymentVo.setVehicleName(byId1.getCarNumber());

            Status byId2 = service.getById(records.get(i).getStatusId());
            parkingPaymentVo.setStatusName(byId2.getStatusName());

            parkingPaymentVos.add(parkingPaymentVo);

        }

        parkingPaymentVoPage.setRecords(parkingPaymentVos);
        return AjaxResult.success(parkingPaymentVoPage);
    }

    @Override
    public AjaxResult ParkingPaymentListApp(ParkingPaymentDto parkingPaymentDto) {
        Page<ParkingPayment> parkingPaymentPage = new Page<>(parkingPaymentDto.getPageNum(), parkingPaymentDto.getPageSize());

        Page<ParkingPaymentVo> parkingPaymentVoPage = new Page<>(parkingPaymentDto.getPageNum(), parkingPaymentDto.getPageSize());

        LambdaQueryWrapper<ParkingPayment> parkingPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();

        Page<ParkingPayment> page = this.page(parkingPaymentPage, parkingPaymentLambdaQueryWrapper);

        List<ParkingPaymentVo> parkingPaymentVos = new ArrayList<>();
        List<ParkingPayment> records = page.getRecords();
        for (int i = 0; i < records.size(); i++) {
            ParkingPaymentVo parkingPaymentVo = new ParkingPaymentVo();
            BeanUtils.copyBeanProp(parkingPaymentVo,records.get(i));
            Parking byId = parkingService.getById(records.get(i).getParkingId());
            Vehicle byId1 = vehicleService.getById(byId.getVehicleId());

            parkingPaymentVo.setVehicleName(byId1.getCarNumber());

            Status byId2 = service.getById(records.get(i).getStatusId());
            parkingPaymentVo.setStatusName(byId2.getStatusName());

            parkingPaymentVos.add(parkingPaymentVo);

        }

        parkingPaymentVoPage.setRecords(parkingPaymentVos);
        return AjaxResult.success(parkingPaymentVoPage);    }
}




